package com.jk.testsql.controller;

import com.jk.testsql.dto.SysUser;
import com.jk.testsql.pojo.ResponseResult;
import com.jk.testsql.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "用户管理模块")
@Slf4j
@RestController
@RequestMapping(value = "sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "用户列表查询", httpMethod = "POST", notes = "用户列表查询")
    @RequestMapping(value = "findSysUserList")
    public ResponseResult<List<SysUser>> findSysUserList(@RequestBody SysUser sysUser) {
        return new ResponseResult<>(200, "查询成功！", sysUserService.findSysUserList(sysUser));
    }

    @ApiOperation(value = "用户新增", httpMethod = "POST", notes = "用户新增")
    @RequestMapping(value = "addSysUser")
    public ResponseResult addSysUser(@RequestBody SysUser sysUser) {
        try {
            sysUserService.addSysUser(sysUser);
            return new ResponseResult(200, "用户新增成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(444, "用户新增失败！");
        }
    }
}
